# -*- coding: utf-8 -*-

# @Author : guoxin

# @Time : 2024/5/29 15:12

# @QQ :363673234

from selenium.webdriver.common.by import By

from base.AddGoodsBase import AddGoodsBase

from base.ObjectMap import ObjectMap

import pyautogui

from time import sleep


class AddGoodsPage(AddGoodsBase, ObjectMap):

    def click_addgoods(self, driver):
        """
        点击新增货源
        :param driver:
        :param menu_name:
        :return:
        """
        addgoods_xpath = self.addgoods_button()
        return self.element_click(driver, By.XPATH, addgoods_xpath)

    def addgoods_input_value(self, driver, input_placeholder, input_value):
        """
        登录页输入值
        :param driver:
        :param input_placeholder:
        :param input_value:
        :return:
        """
        input_xpath = self.addgoods_input(input_placeholder)
        return self.element_fill_value(driver, By.XPATH, input_xpath, input_value)

    def click_carriericon(self, driver):
        '''
        承运商下标
        :param driver:
        :return:
        '''
        icon_xpath = self.addgoods_selecetcarriericon()
        return self.element_click(driver, By.XPATH, icon_xpath)

    def addgoods_input_carriervalue(self, driver):
        '''
        承运商输入框
        :param driver:
        :return:
        '''
        carriervalue_xpath = self.addgoods_selecetcarrier()
        return self.element_click(driver, By.XPATH, carriervalue_xpath)

    def click_loadstationedit(self, driver):
        '''
        点击装货站点输入框
        :param driver:
        :param input_placeholder:
        :return:
        '''
        input_xpath = self.addgoods_loadxpatedit()
        return self.element_click(driver, By.XPATH, input_xpath)

    def click_loadstation(self, driver):
        '''
        点击装货站点
        :param driver:
        :return:
        '''
        loadstation_xpath = self.addgoods_onloadstation()
        return self.element_click(driver, By.XPATH, loadstation_xpath)

    def click_unloadstationedit(self, driver, input_value):
        """
        卸货站点输入框
        :param driver:
        :param input_placeholder:
        :param input_value:
        :return:
        """
        input_xpatho = self.addgoods_unloadxpatedit()
        # return self.element_fill_value(driver, By.XPATH,input_xpatho, input_value)
        return self.element_click(driver, By.XPATH, input_xpatho)

    def click_unloadstation(self, driver):
        '''
        点击卸货站点
        :param driver:
        :return:
        '''
        unloadstation_xpath = self.addgoods_unloadxpath()
        return self.element_click(driver, By.XPATH, unloadstation_xpath)

    def unloadstation(self):
        pyautogui.click(518, 704)

    def addgoods_goodsType(self):
        pyautogui.click(443, 723)

    def addgoods_goodsName(self):
        pyautogui.click(981, 729)

    def addgoods_submit_click(self, driver):
        '''
        货源提交
        :param driver:
        :return:
        '''
        submitbutton_xpath = self.addgoods_submitbutton()
        return self.element_click(driver, By.XPATH, submitbutton_xpath)

    def addgoods_goodsType_click(self, driver, input_placeholder):
        '''
        货物类型输入框
        :param driver:
        :param input_placeholder:
        :return:
        '''
        goods_typexpath = self.addgoods_input(input_placeholder)
        return self.element_click(driver, By.XPATH, goods_typexpath)

    def addgoods_tpyeselect_click(self, driver):
        '''
        货物类型选择点击
        :param driver:
        :return:
        '''
        selecttype_xpath = self.adddgoos_goosTypexpath()
        return self.element_click(driver, By.XPATH, selecttype_xpath)

    def addgoods_goodNameselect_click(self, driver):
        '''
        货物名称点击
        :param driver:
        :return:
        '''
        goodsNanme_xpath = self.addgoods_goosNamexpath()
        return self.element_click(driver, By.XPATH, goodsNanme_xpath)
    def addgoods_good(self,driver,goodsName,distance,transportTime,freight):
        '''
        新增货源
        :param driver:
        :param goodsName: 货源成名
        :param distance: 运距
        :param transportTime: 运输时长
        :param freight: 运价
        :return:
        '''
        self.click_addgoods(driver)
        self.addgoods_input_value(driver, "请输入货源名称",goodsName)
        self.click_carriericon(driver)
        self.addgoods_input_carriervalue(driver)
        self.click_loadstationedit(driver)
        sleep(1)
        self.click_loadstation(driver)
        self.click_unloadstationedit(driver, "人寿山")
        sleep(1.3)
        self.unloadstation()
        self.addgoods_goodsType_click(driver,"请选择货物类型")
        sleep(1.3)
        self.addgoods_goodsType()
        self.addgoods_goodsType_click(driver, "请输入货物名称")
        sleep(1.3)
        self.addgoods_goodsName()
        self.addgoods_input_value(driver,"请输入运距", distance)
        self.addgoods_input_value(driver, "请输入预估运输时长", transportTime)
        self.addgoods_input_value(driver, "请输入运价", freight)
        sleep(1.3)
        self.addgoods_submit_click(driver)
        sleep(1.5)






